package jsyf.oa.web.tmp;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.OssClient;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.tmp.OilFacade;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.InputStream;
import java.util.UUID;


/**
 * Created by jjx on 2018/3/6.
 */

@Api(value = "区域经理油量", description = "区域经理油量")
@Controller
@RequestMapping("/oil")
public class OilController {

    @Resource
    private OilFacade oilFacade;/*相应接口*/

    private JSONObject jsonObj = null;

    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "记录添加",
            notes = "记录添加 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'createUserId':'1'}", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        ResponseUtils.putJsonResponse(response, oilFacade.add(jsonData));
    }

    @ResponseBody
    @RequestMapping(value = "/getById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过ID查找",
            notes = "通过ID查找 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'id':'AF17BAFDFCF74AF78DA8C285F88F1C83'}", dataType = "String", paramType = "body")
    public void getById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = oilFacade.getById(jsonData);
        String result = "";
        if (null != records) {
            result = BaseUtils.succsessObjRespond(records);
        } else {
            result = BaseUtils.errorrRespond("查找失败");
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过ID标记删除",
            notes = "通过ID标记删除 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String result = "";
        if (oilFacade.delById(jsonData)) {
            result = BaseUtils.succsessObjRespond("删除成功");
        } else {
            result = BaseUtils.errorrRespond("删除失败");
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过ID永久删除",
            notes = "通过ID永久删除 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String result = "";
        if (oilFacade.removeById(jsonData)) {
            result = BaseUtils.succsessObjRespond("删除成功");
        } else {
            result = BaseUtils.errorrRespond("删除失败");
        }
        ResponseUtils.putJsonResponse(response, result);
    }

    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过ID修改",
            notes = "通过ID修改 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String result = "";
        if (oilFacade.update(jsonData)) {
            result = BaseUtils.succsessObjRespond("修改成功");
        } else {
            result = BaseUtils.errorrRespond("修改失败");
        }
        ResponseUtils.putJsonResponse(response, result);
    }

}
